<%@page import="com.aring.bean.TimeTable"%>
<%@page import="com.aring.bean.School"%>
<%@page import="com.aring.bean.Place"%>
<%@page import="com.aring.bean.PlaceNumber"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	    <title>场地预定</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="../css/time.css" rel="stylesheet" type="text/css" media="screen">
		<script type="text/javascript" src="../js/jquery-1.9.0.min.js"></script>
		
	</head>
	<body>
	<% List<PlaceNumber> placeNumbers = (List<PlaceNumber>)session.getAttribute("placeNumbers");
	   int placeId = Integer.valueOf(request.getParameter("placeId"));
	   List<Place> places = (List<Place>)session.getAttribute("places");
	   Place currentPlace = new Place();
	   List<TimeTable> tables = (List<TimeTable>)session.getAttribute("tables");
	   for(Place place: places) 
		   if(place.getP_no()==placeId) {
			   currentPlace = place;
			   break;
		   }
	   School school = (School)session.getAttribute("currentSchool");
	%>
		<ul id="nav">
			<h2 class="R-h2"><span>当前位置：<a href="../index.jsp">首 页</a> &gt; <a href="#"><%=school.getName()%></a> 
			&gt; <a href="#"><%=currentPlace.getType()%></a> &gt;<a href="#">预定</a></span><label>场地预定</label></h2> 
		</ul>
		
		<div class="Main">
			<ul class="News_ul"> 		   			   
			    <li>
			    <form action="../getTimeTable.do" method="get">
			    	<div class="input-tips">
						<label for="user">场号：</label>
					</div>
					<input type="hidden" name="placeId" value="<%=placeId%>" >
					<input type="hidden" name="pageName" value="redirect:/user/timeTable.jsp" >
					<div class="inputOuter">
						<select name="placeNumberId" style="width:60px;height: 30px;" id="placeNumberSelect">
							<% if(placeNumbers !=null){
								for(PlaceNumber placeNumber: placeNumbers){%>
							<option value="<%=placeNumber.getId()%>"><%=placeNumber.getPlaceNo()%>号场</option>		
							<% }}%>				    
					    </select>
					</div>
					<div class="inputOuter">
					<input type="submit"  class="button_blue" value="查询" id="confirm"/>		
					</div>	
				</form>		
				</li>
			</ul>
			<ul class="info">
				<table border="1">
				<tr>
				<th width="160px">星期</th>
				<th width="160px">时间段</th>
				<th width="160px">租金</th>
				<th width="160px">状态</th>
				<th width="160px">预定</th>
				</tr>
				<tbody>
				<%  boolean flag = true;
				    String status = "可预定";
				    if(tables!=null){
					for(TimeTable table : tables){
					  if(table.getStatus()!=0){
						  status = "不可预定";
						  flag = false;
					  }else{
						   flag = true;
						   status = "可预定"; 
					  }
					%>
				<tr>
					<td><%=table.getWeekday()%></td>
					<td><%=table.getTime() %></td>
					<td><%=table.getRent() %>元</td>
					<td><%=status%></td>
					<% if(flag){%> <td><a href="../reserve.do?tId=<%=table.getId()%>&placeId=<%=placeId %>&placeNumberId=<%=table.getPlaceNumberId() %>" style="color: white;">预定</a></td>				
					<%}else {%> <td>已被预订</td>
					<%}%>
				</tr>
				<%}}%>
				</tbody>
				</table>
			</ul> 
		</div>
		
		<script type="text/javascript">
		$(document).ready(function(){
			var placeNumber = getUrlParam('placeNumberId');
			if(placeNumber){
				$('#placeNumberSelect').find('option[value='+(placeNumber)+']').attr('selected',true);
			}
		});
			
		
		function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }
	</script>
	</body>
	
</html>